//----BEGIN LICENSE----//
/*****************************************************************\
** prevalentLite - sqlite3 persistence object library 
**
** Copyright (C) 2008 Philip R. Schuchardt
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program.  If not, see <http://www.gnu.org/licenses/>.
**
*****************************************************************/
//----END LICENSE----//



/*!
  \class plInt plInt.h <plInt>
  \brief plInt is a database aware integer.

  plInt can be used and should be used in the same way as a normal integer.  Make sure plInt::Setup() is called before using the class.  Without calling plInt::Setup(), the database doesn't know how to get or commit data.

  For example:
  \code

  plInt testInt;
  testInt.Setup("testInt", this);
  testInt = 5;
  testInt += 10;
  testInt = testInt * testInt;

  int temp = testInt;
  temp = 1000;
  testInt = temp;

   \endcode

  */

//Our includes
#include "plInt.h"
#include "plDatabase.h"
#include "plObject.h"

//////////////////////////////////////////////// Public ////////////////////////////////////////////////////

//Constructor
plInt::plInt() : plData() {
	//Cached = false;
}

//Constructor
plInt::plInt(int value) : plData() {
	Value = value;
	Disabled = true;
}

//Copy constructor
plInt::plInt(const plInt& obj) : plData(obj) {
	Copy(obj);
}

//Accessor
int plInt::Data() {
        plData::GetData();
	return Value;
}

//Modifier
void plInt::SetData(int value) {
	Value = value;
        plData::SetData();
}

	
//Operator overloading
void plInt::operator=(int value) {
	SetData(value);
}

//Operator overloading
void plInt::operator=(const plInt& obj) {
	Copy(obj);
}

plInt::operator int() {
	return Data();
}

//Binds the data with the statement
void plInt::Bind(sqlite3_stmt* statement, int index) const {
	sqlite3_bind_int(statement, index, Value);
}

//Gets the data from the current statement
void plInt::Column(sqlite3_stmt* statement, int index ) {
	Value = sqlite3_column_int(statement, index);
}

//Does a smart copy of the object
void plInt::Copy(const plInt& obj) {
	SetData(obj.Value);
}


